package com.cloud.fork.controller;

import com.cloud.fork.domain.Context;
import com.cloud.fork.service.CombineLoadDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ForkJoinPool;

@RestController
public class ForkController {

    @Autowired
    CombineLoadDataService combineLoadDataService;

    @RequestMapping("/task")
    public Context getData() {
        Context context = new Context();
        combineLoadDataService.setContext(context);
        ForkJoinPool forkJoinPool = new ForkJoinPool(3);
        forkJoinPool.submit(combineLoadDataService);
        return combineLoadDataService.getContext();
    }

    @RequestMapping("/fork/error")
    public Context error() {
        throw new RuntimeException("error!!!");
    }

}
